//表单验证
$(function(){
	$('#saveShopBtn').click(function () {
		//获取验证器
		var id = $('#id').val();
		var name = $('#name').val();
		var code = $('#code').val();
		var weixinQrCodeImage = $('#weixinQrCodeImage').attr("src");
		var zhifubaoQrCodeImage = $('#zhifubaoQrCodeImage').attr("src");
		var logoImage = $('#logoImage').attr("src");
		var description = $('#description').val();
		//地址信息
		var province = $('#province').val();
		var city = $('#city').val();
		var address = $('#address').val();
		if(code == null || code == ""){
			layer.msg("请输入店铺编码,以方便您店铺的推广!",{icon:2,time:2000});
			return;
		}
		if(!isCode(code)){
			layer.msg("亲,编码只能是英文字母和数字组合,不区分大小写哦!",{icon:2,time:2000});
			return;
		}
		if("admin" == code){
			layer.msg("亲,编码不能是admin系统关键字哦!",{icon:2,time:2000});
			return;
		}
		if(code.length > 32){
			layer.msg("店铺编码不能超过32位,越短越好哦!",{icon:2,time:2000});
			return;
		}
		if(name == null || name == ""){
			layer.msg("请为您的店铺起个响亮的名字,以便客户能快速记住!",{icon:2,time:2000});
			return;
		}
		if(name.length > 32){
			layer.msg("姓名不能超过32位!",{icon:2,time:2000});
			return;
		}
		if(weixinQrCodeImage == null || weixinQrCodeImage == ""){
			layer.msg("请上传微信收钱码,方便客户向您付款!",{icon:2,time:2000});
			return;
		}
		if(weixinQrCodeImage.length > 512){
			layer.msg("微信收钱码url不能超过512位!",{icon:2,time:2000});
			return;
		}
		
		if(zhifubaoQrCodeImage == null || zhifubaoQrCodeImage == ""){
			layer.msg("请上传支付宝收钱码,方便客户向您付款!",{icon:2,time:2000});
			return;
		}
		if(zhifubaoQrCodeImage.length > 512){
			layer.msg("支付宝收钱码url不能超过512位!",{icon:2,time:2000});
			return;
		}
		if(logoImage == null || logoImage == ""){
			layer.msg("请上传您店铺的logo!",{icon:2,time:2000});
			return;
		}
		if(description != null && description.length > 512){
			layer.msg("店铺描述不能超过512位!",{icon:2,time:2000});
			return;
		}
		var shop = {};
		shop["id"] = id;
		shop["code"] = code;
		shop["name"] = name;
		shop["weixinQrCode"] = weixinQrCodeImage;
		shop["zhifubaoQrCode"] = zhifubaoQrCodeImage;
		shop["logo"] = logoImage;
		shop["description"] = description;
		//地址信息
		shop["province"] = province;
		shop["city"] = city;
		shop["address"] = address;
		
		$('#saveShopBtn').attr("disabled",true);
		$.ajax({
			url:baselocation+'/shop-update',
			contentType:'application/json',
			type:'post',
			dataType:'json',
			data: JSON.stringify(shop),
			success:function(result){
				$('#saveShopBtn').attr("disabled",false);
				if(result.success==false){
					layer.msg(result.message,{icon:2,time:2000});
				}else{
					window.location.href=baselocation+'/shop-info';
				}
			},
			error:function(result){
				alert("系统异常,请联系管理员！");
			}
		});
	})
});